package com.yufubao.api.controller.management.system;

import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.result.PageUtils;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.dto.management.sys.ChangeStatusDto;
import com.yufubao.model.dto.management.sys.SaveRoleMenuDto;
import com.yufubao.model.dto.management.sys.UpdateRoleMenuDto;
import com.yufubao.service.service.management.authorization.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2024/9/12 17:59
 */
@Api("角色管理")
@RestController
@RequestMapping("/applet/management/sys/role")
public class SysRoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 角色分页查询
     */
    @RequestMapping(value = "/pageList", method = RequestMethod.POST)
    @ApiOperation(value = "角色分页查询")
    @SystemLog(info = "角色分页查询")
    public ResponseResult pageList(@RequestBody Map<String, Object> params) {
        PageUtils page = roleService.queryPage(params);

        return ResponseResult.okResultPage("page", page);
    }

    /**
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @description 修改状态
     * @author 31115
     * @date 2022/12/7 15:10
     */
    @RequestMapping(value = "/changeStatusById", method = RequestMethod.PUT)
    @ApiOperation(value = "修改状态")
    @SystemLog(info = "修改状态")
    public ResponseResult changeStatusById(@RequestBody ChangeStatusDto dto) {
        return roleService.changeStatusById(dto);
    }


    /**
     * @description 新增角色
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 21:12
     */
    @RequestMapping(value = "/saveRoleMenu", method = RequestMethod.POST)
    @ApiOperation(value = "新增角色")
    @SystemLog(info = "新增角色")
    public ResponseResult saveRoleMenu(@RequestBody @Validated SaveRoleMenuDto saveRoleMenuDto){
        return roleService.saveRoleMenu(saveRoleMenuDto);
    }

    /**
     * @description 修改角色回显
     * @param id
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 21:41
     */
    @RequestMapping(value = "/selectRoleById/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "修改角色回显")
    @SystemLog(info = "修改角色回显")
    public ResponseResult selectRoleById(@PathVariable("id") Long id){
        return roleService.selectRoleById(id);
    }

    /**
     * @description 修改角色
     * @param updateRoleMenuDto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 22:40
     */
    @RequestMapping(value = "/updateRole", method = RequestMethod.PUT)
    @ApiOperation(value = "修改角色")
    @SystemLog(info = "修改角色")
    public ResponseResult updateRole(@RequestBody @Validated UpdateRoleMenuDto updateRoleMenuDto){
        return roleService.updateRole(updateRoleMenuDto);
    }

    /**
     * @description 批量删除
     * @param ids
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 0:11
     */
    @RequestMapping(value = "/deleteRoleByIds", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除")
    @SystemLog(info = "批量删除")
    public ResponseResult deleteRoleByIds(@RequestBody  Long[] ids){
        return roleService.deleteRoleByIds(ids);
    }

    /**
     * @description 查询角色列表接口
     * @param
     * @return
     * @author 31115
     * @date 2022/12/8 9:31
     */
    @RequestMapping(value = "/listAllRole", method = RequestMethod.GET)
    @ApiOperation(value = "查询角色列表接口")
    @SystemLog(info = "查询角色列表接口")
    public ResponseResult listAllRole(){
        return roleService.listAllRole();
    }


}
